export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const { location, keywords, radius = 3000, types } = query;
  
  // 高德地图API密钥
  const AMAP_KEY = 'ea14acfbeff3ab37b1a0ac893135a7e8';
  
  try {
    if (!location) {
      throw createError({
        statusCode: 400,
        statusMessage: '缺少必要参数：location'
      });
    }
    
    // 构建查询参数
    const params = new URLSearchParams({
      key: AMAP_KEY,
      location: location as string,
      radius: radius as string,
      output: 'json',
      extensions: 'all'
    });
    
    if (keywords) {
      params.append('keywords', keywords as string);
    }
    
    if (types) {
      params.append('types', types as string);
    }
    
    const response = await fetch(
      `https://restapi.amap.com/v3/place/around?${params.toString()}`
    );
    const poiData = await response.json();
    
    if (poiData.status === '1') {
      return {
        success: true,
        data: poiData.pois || [],
        count: poiData.count,
        message: 'POI搜索成功'
      };
    } else {
      throw createError({
        statusCode: 500,
        statusMessage: `POI搜索API错误: ${poiData.info}`
      });
    }
  } catch (error) {
    console.error('POI搜索API调用失败:', error);
    throw createError({
      statusCode: 500,
      statusMessage: 'POI搜索失败'
    });
  }
}); 